from tools_algorithm import *


class Solution:
    def numberOfPairs(self, points: List[List[int]]) -> int:
        points.sort(key=lambda a: (a[0], -a[1]))
        cntx, cnty = Counter(), Counter()
        ans, n = 0, len(points)
        for i, (a, b) in enumerate(points):
            cntx[a] += 1
            cnty[b] += 1
            x, y = a, -inf if i == n - 1 or points[i + 1][0] != a else points[i + 1][1]
            for j in range(i + 1, n):
                if points[j][1] == b:
                    break
                if points[j][0] > x and points[j][1] < b and points[j][1] > y:
                    ans += 1
                    x, y = points[j]
        for k, v in cntx.items():
            ans += v - 1
        for k, v in cnty.items():
            ans += v - 1

        return ans


s = Solution()
print(s.numberOfPairs([[2, 5], [6, 4], [3, 2], [4, 5]]))
# print(s.numberOfPairs([[0, 3], [2, 4], [0, 6]]))
# print(s.numberOfPairs([[3, 1], [1, 3], [1, 1]]))
